@extends('back_end.layouts.default_info')

{{-- Web site Title --}}
@section('title')
{{{ Lang::get('general.back_end.order').Lang::get('general.index') }}} :: @parent
@stop
@section('content_header')
{{{ Lang::get('general.back_end.order').Lang::get('general.index') }}}
@stop
{{-- breadcrumb --}}
@section('breadcrumb')
<li><a href="#"><i class="fa fa-dashboard"></i> {{{ Lang::get('general.back_end.home') }}}</a></li>
<li class="active">{{{ Lang::get('general.back_end.order').Lang::get('general.index') }}}</li>
@stop
{{-- Content --}}
@section('content')

<div class="box box-success box-search">
    {{ Form::open(array('action' => 'BackFoodController@getIndex')) }}
    <div class="box-header" style="cursor: move;">
        <i class="ion ion-clipboard"></i>

        <h3 class="box-title">查询</h3>
        <div class="box-tools pull-right">

        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        {{ $tab_index = 1 ? '' : '' }}
        {{ $tab_index++ }}

        {{ Form::checkboxGroup('status', Order::$column['status'], $status_for_display, $errors, $tab_index++) }}
        {{ Form::checkboxGroup('payment_type', Order::$column['payment_type'], $payment_type_display, $errors, $tab_index++) }}

        {{ Form::textBetweenGroup('total_price', Order::$column['total_price'], isset($links['total_price_start']) ? $links['total_price_start'] : '', isset($links['total_price_end']) ? $links['total_price_end'] : '', $errors, $tab_index++) }}

        {{ Form::datetimeBetweenGroup('created_at', Order::$column['created_at'], isset($links['created_at_start']) ? $links['created_at_start'] : date('Y-m-d', time()), isset($links['created_at_end']) ? $links['created_at_end'] : date('Y-m-d', time()), $errors, $tab_index++) }}


    </div>
    <!-- /.box-body -->
    <div class="box-footer clearfix no-border">
        <button type="submit" class="btn btn-primary pull-left btn-find" style="margin-left: 10px;"><i class="fa fa-search"></i> {{{ Lang::get('button.find') }}}</button>
        <button type="submit" data-type="excel" class="btn btn-default pull-left btn-export" style="margin-left: 10px;"><i class="fa fa-table"></i> {{{ Lang::get('button.export_excel') }}}</button>
        <button type="submit" data-type="csv" class="btn btn-default pull-left btn-export" style="margin-left: 10px;"><i class="fa fa-vimeo-square"></i> {{{ Lang::get('button.export_csv') }}}</button>
    </div>
    {{ Form::close() }}
</div>

<div class="box box-primary">
    <div class="box-header" style="cursor: move;">
        <i class="ion ion-clipboard"></i>

        <h3 class="box-title">结果</h3>

        <div class="box-tools pull-right">
            <?php echo $entries->links(); ?>
        </div>
    </div>
    <!-- /.box-header -->
    <div class="box-body">
        <ul class="todo-list ui-sortable">
            <table class="table table-hover">
                <tbody><tr>
                    <th class="col-xs-2">{{ Form::orderLink($links, 'ID', 'id', true) }}</th>
                    <th class="col-xs-2">{{ Form::orderLink($links, Order::$column['total_price'], 'total_price', true) }}</th>
                    <th class="col-xs-1">{{ Form::orderLink($links, Order::$column['status'], 'status') }}</th>
                    <th class="col-xs-1">{{ Form::orderLink($links, Order::$column['payment_type'], 'status') }}</th>
                    <th class="col-xs-2">{{ Form::orderLink($links, Order::$column['created_at'], 'created_at', true) }}</th>
                    <th class="col-xs-2">{{{ Lang::get('table.actions') }}}</th>
                </tr>
                @foreach ($entries as $entry)
                <tr>
                    <th class="col-xs-2">{{ $entry->id }}</th>
                    <th class="col-xs-2">{{ $entry->total_price }}</th>
                    <th class="col-xs-1">{{ Order::$statuses[$entry->status]['display_name'] }}</th>
                    <th class="col-xs-1">{{ isset($entry->payment_type)?Order::$paymentTypes[$entry->payment_type]['display_name'] : '未知方式'}}</th>
                    <th class="col-xs-2">{{ $entry->created_at }}</th>
                    <th class="col-xs-2">
                        @if (Auth::user()->can('show_order'))
                        <a href="{{{ URL::action('BackOrderController@getDetail', $entry->id) }}}" class="iframe btn btn-xs btn-default"><i class="fa fa-eye"></i> {{{ Lang::get('button.view') }}}</a>
                        @endif
                    </th>
                </tr>
                @endforeach
                </tbody></table>

        </ul>
        <span style="color: red;">订单金额：{{ $sum }}元</span>
    </div>
    <!-- /.box-body -->
    <div class="box-footer clearfix no-border">
    </div>
</div>

@stop

{{-- Scripts --}}
@section('scripts')
<script type="text/javascript">
    $(function () {

        'use strict';

        $('input[name="created_at_start"]').datetimepicker({
            format: 'yyyy-mm-dd',
            language:'zh-CN',
            minView:'month',
            startView:'month',
            startDate: "1970-01-01",
            endDate: "2115-01-01"
        });
        $('input[name="created_at_end"]').datetimepicker({
            format: 'yyyy-mm-dd',
            language:'zh-CN',
            minView:'month',
            startView:'month',
            startDate: "1970-01-01",
            endDate: "2115-01-01"
        });
        $('.fa-calendar').parent('div').click(function(){
            $('input[name="created_at_start"]').datetimepicker('show');
            $('input[name="created_at_end"]').datetimepicker('show');
        });

        $('form button.btn-export').click(function(event){
            event.preventDefault();
            $('.box-search form').attr('target', "_blank");
            $('.box-search form').attr("action","{{ URL::to('back_end/orders/export') }}?type="+$(this).attr('data-type'));
            $('.box-search form').submit();
        });

        $('form button.btn-find').click(function(event){
            event.preventDefault();
            $('.box-search form').attr('target', "_self");
            $('.box-search form').attr("action","{{ URL::to('back_end/orders') }}");
            $('.box-search form').submit();
        });

    });
</script>
@stop
